package anthology.daily_question._25_02;
//https://leetcode.cn/problems/sort-array-by-parity-ii/description/?envType=daily-question&envId=2025-02-04
public class _0922按奇偶排序数组2 {
    class Solution {
        public int[] sortArrayByParityII(int[] nums) {
            int n = nums.length;
            int[] ans = new int[n];

            int i = 0;
            for (int x : nums) {
                if (x % 2 == 0) {
                    ans[i] = x;
                    i += 2;
                }
            }
            i = 1;
            for (int x : nums) {
                if (x % 2 == 1) {
                    ans[i] = x;
                    i += 2;
                }
            }
            return ans;
        }
    }
}
